from qfluentwidgets import MessageBoxBase, LineEdit, ComboBox, SubtitleLabel
from PySide6.QtWidgets import QGridLayout, QLabel
from PySide6.QtCore import Qt
from PySide6.QtGui import QFont


class BaseStudentDilalog(MessageBoxBase):
    def __init__(self, title, parent=None):
        super().__init__(parent)
        self.title = title
        self.setup_ui()

    def setup_ui(self):
        self.titleLabel = SubtitleLabel(self.title, self)
        self.viewLayout.addWidget(self.titleLabel)
        self.viewLayout.setAlignment(self.titleLabel, Qt.AlignmentFlag.AlignCenter)

        grid_layout = QGridLayout()
        self.viewLayout.addLayout(grid_layout)

        self.nameInput = LineEdit(self)
        self.numberInput = LineEdit(self)
        self.genderCombo = ComboBox(self)
        self.genderCombo.addItems(["男", "女"])
        self.classCombo = ComboBox(self)
        self.chineseInput = LineEdit(self)
        self.mathInput = LineEdit(self)
        self.englishInput = LineEdit(self)

        fields = [
            ("姓名: ", self.nameInput),
            ("学号: ", self.numberInput),
            ("性别: ", self.genderCombo),
            ("班级: ", self.classCombo),
            ("语文: ", self.chineseInput),
            ("数学: ", self.mathInput),
            ("英语: ", self.englishInput),
        ]

        for row, (label_text, widget) in enumerate(fields):
            label_widget = QLabel(label_text)
            font = QFont("微软雅黑")
            font.setBold(True)
            label_widget.setFont(font)
            grid_layout.addWidget(label_widget, row, 0)
            grid_layout.addWidget(widget, row, 1)

        grid_layout.setColumnStretch(1, 1)
        grid_layout.setAlignment(Qt.AlignmentFlag.AlignLeft)

        self.yesButton.setText("确定")
        self.cancelButton.setText("取消")

        for widget in [field[1] for field in fields]:
            widget.setMinimumWidth(200)

        self.nameInput.setFocus()

        self.yesButton.setDefault(False)
        self.yesButton.setAutoDefault(False)


class AddStudentDilalog(BaseStudentDilalog):
    def __init__(self, parent=None):
        super().__init__("添加学生", parent)
        self.student_id = None
        self.yesButton.setText("添加")
